<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:rich="http://richfaces.ajax4jsf.org/rich"
	xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
	xmlns:t="https://code.google.com/p/rad-framework/taglib"
	xmlns:tt="https://code.google.com/p/rad-framework"
	xmlns:s="http://jboss.com/products/seam/taglib" template="#{theme.layout}">
	
	<ui:param name="title" value="#{finder.title}" />
	
	<ui:define name="left">
		<ui:include src="/themes/default/includes/search-sidebar.xhtml"/>
	</ui:define>
	<ui:define name="crumbs">
	</ui:define>
	
	<ui:define name="center">
		<f:view>							
			<h:form id="searchForm">
				
				<ui:param name="reRender" value="searchTable,pagingGrid"/>
				
				<rich:spacer width="1" height="1"/>
				
				<rich:dataTable id="searchTable" value="#{finder.result}" var="row" width="100%">
					
					<f:facet name="header">
						<rich:columnGroup>
							
							<ui:insert name="headers">
								<c:forEach items="#{columnTypes}" var="c">
									<tt:columnSortHeader 
										label="#{c.label}"
										property="#{c.name}" 
										rendered="#{c.rendered}" />
								</c:forEach>
							</ui:insert>
							
							<h:column
								rendered="#{renderAction}">
								<h:outputText id="ActionLabel"
									value="#{messages['Action']}"/>
							</h:column>

						</rich:columnGroup>
					</f:facet>
					
					<rich:columnGroup>
						
						<ui:insert name="columns">
							<c:forEach items="#{columnTypes}" var="c">
								<tt:column 
									type="#{c.type}" 
									value="#{c.value}"
									rendered="#{c.rendered}" />
							</c:forEach>
						</ui:insert>
						
						<h:column
							rendered="#{renderAction}" width="10%" styleClass="rad-framework-action-table-cell">
							<ui:insert name="actions">
								<tt:link id="viewLink"
									path="#{finderViewPath}"
									entityName="#{entityName}"
									mode="View"
									key="#{row.id}"
									rendered="#{renderView}"
									styleClass="rad-framework-form-link">
									<h:graphicImage
										value="#{messages['ViewIcon']}"
										border="0" title="#{messages['View']}"/>
								</tt:link>
								
								<tt:link id="editLink"
									path="#{finderViewPath}"
									entityName="#{entityName}"
									mode="Edit"
									key="#{row.id}"
									rendered="#{renderEdit}"
									styleClass="rad-framework-form-link">
									<h:graphicImage
										value="#{messages['EditIcon']}"
										border="0" title="#{messages['Edit']}"/>
								</tt:link>
								
								<h:outputLink id="printDetailLink"
									value="#{contextPath}/pdf/#{finderViewPath}#{entityName}/#{entityName}.seam"
									rendered="#{renderPrintDetails}"
									styleClass="rad-framework-form-link"
									target="_blank">
									<f:param name="id" value="#{row.id}"/>
									<h:graphicImage
										value="/themes/default/images/icons/ico-app-print.png" border="0"
										title="#{messages['Print']}"/>
								</h:outputLink>

								<a4j:commandLink id="deleteLink"
									action="#{finder.delete}"
									rendered="#{renderDelete}"
									eventsQueue="viewQ"
									reRender="searchForm,pagingGrid,recent"
									styleClass="rad-framework-form-link"
									onclick="if (!confirm('#{messages['DeleteConfirmation']}')) return false">
									<h:graphicImage
										value="#{messages['DeleteIcon']}"
										border="0"
										title="#{messages['Delete']}"/>
									<f:param name="id" value="#{row.id}"/>
								</a4j:commandLink>
							</ui:insert>
						</h:column>
					</rich:columnGroup>
				</rich:dataTable>
						
				<rich:jQuery selector="#searchTable tr:odd" query="addClass('rad-framework-row-odd')" />
				<rich:jQuery selector="#searchTable tr:even" query="addClass('rad-framework-row-even')" />
				<rich:jQuery selector="#searchTable tr" query="mouseover(function(){jQuery(this).addClass('rad-framework-row-over')})"/>
				<rich:jQuery selector="#searchTable tr" query="mouseout(function(){jQuery(this).removeClass('rad-framework-row-over')})"/>
				
				<ui:insert name="pagingPanel">
					<ui:include	src="includes/pager.xhtml">
						<ui:param name="reRender" value="searchTable,pagingGrid"/>
					</ui:include>
				</ui:insert>
				
			</h:form>
			<c:if test="#{renderQuickAdd}">
				<div id="view-panel">
					<ui:insert name="quickAddPanel">
						<rich:spacer width="1" height="1"/>
						<hr class="rad-framework-horizontal-separator"/>
						<rich:spacer width="1" height="1"/>
						<h:form id="quickAddForm">
							<h:panelGrid columns="1" cellspacing="0"
								id="quickAddGrid" styleClass="rad-framework-quick-add">
								
								<h:panelGrid columns="2" cellpadding="5"
									width="100%"
									columnClasses="rad-framework-form-recordset,rad-framework-record-nav">
									
									<a4j:commandLink id="quickAddButton"
										type="submit"
										eventsQueue="viewQ"
										action="#{finder.quickAdd}"
										reRender="searchTable,pagingGrid,quickAddForm"
										styleClass="rad-framework-button-content">
										<span><h:outputText value="#{messages['Add']}" /></span>
									</a4j:commandLink>
								</h:panelGrid>
								
								<tt:validate-panel>
									<ui:include
										src="/#{viewPath == null ? 'jsf' : viewPath}/#{finder.entityName}/EditPanel.xhtml">
										<ui:param name="entity"
											value="#{editor.instance}"/>
										<ui:param name="label"
											value="#{messages['General']}"/>
									</ui:include>
								</tt:validate-panel>
								
							</h:panelGrid>
						</h:form>
					</ui:insert>
				</div>
			</c:if>
			
			<ui:remove>
			<a4j:region>
				<h:form>
					<a4j:poll id="poll" interval="#{finder.pollingInterval}"
						action="#{finder.find}" 
						enabled="#{finder.pollingEnabled}"
						eventsQueue="viewQ"
						reRender="searchTable,pagingGrid" />
				</h:form>
			</a4j:region>			
			</ui:remove>
			
		</f:view>
	</ui:define>
</ui:composition>